/*
 * Copyright (c) 2010-2011 NOO. All Rights Reserved.
 * [Id:ActionOperatorBean.java  11-10-6 下午5:00 poplar.yfyang ]
 */
package org.mumu.pawn.beans.common;

import org.jboss.logging.Logger;
import org.mumu.pawn.cmps.OperateCmp;
import org.mumu.pawn.domain.Operate;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 请求操作Bean，用来存储系统的操作请求，维持一个Map.
 * </p>
 *
 * @author poplar.yfyang
 * @version 1.0 11-10-6 下午5:00
 * @since JDK 1.5
 */
@Named
@ApplicationScoped
public class ActionOperatorBean implements Serializable {
    private static final long serialVersionUID = 8763754844616857553L;


    /**
     * 初始化请求Map
     */
    @PostConstruct
    protected void init() {
        log.info("初始化操作信息");
        List<Operate> operates = operateCmp.listOperate();
        for (Operate operate : operates) {
            _operateMap.put(operate.getOperateSign(), operate);
        }
    }

    /**
     * 所有的操作请求
     */
    private static Map<String, Operate> _operateMap = new HashMap<String, Operate>();

    @Inject
    private Logger log;
    @Inject
    private OperateCmp operateCmp;

    /**
     * 从缓存中取得操作信息，并将操作信息返回。
     *
     * @param sign 操作标记
     * @return 返回操作信息
     */
    public Operate getOperate(String sign) {
        return _operateMap.get(sign);
    }

    /**
     * 定时刷新操作请求
     */
    private class RefushOperate extends Thread {
        @Override
        public void run() {
            super.run();
        }
    }


}
